package com.sqlist.share.connection;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * Created by SqList on 2018/6/11.
 */

public class ClientInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
//        ch.pipeline()
//                .addLast(new ObjectDecoder(1024 * 1024, ClassResolvers.cacheDisabled(this.getClass().getClassLoader())))
//                .addLast(new ObjectEncoder())
//                .addLast(new ClientHandler());

        ch.pipeline()
                .addLast(new DelimiterBasedFrameDecoder(8192, Unpooled.copiedBuffer("|".getBytes())))
                .addLast(new StringDecoder())
                .addLast(new StringEncoder())
                .addLast(new ClientHandler());
    }
}
